package com.dycs.utils.old;

public class JsonKeyValueIterator {

    private String str;

    public JsonKeyValueIterator(String str) {
        this.str = str;
    }

    public String getNextKeyValue() {

        String keyValue;
        if (!hasNextKeyValue()){
            keyValue = null;
        } else {
            int index = str.indexOf(',');
            if (index < 0){
                keyValue = str.trim();
                str = "";
            }else {
                keyValue = str.substring(0,index).trim();
                if (str.length()-1 == index){
                    str = "";
                }else {
                    str = str.substring(index+1);
                }
            }
        }
        return keyValue;
    }

    public Boolean hasNextKeyValue() {

        return !("".equals(str) || ",".equals(str) || str == null);
    }
}
